package com.ludashi.weather;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @author : xfhy
 * Create time : 2021/3/1 19:24
 * Description :
 */
public class TestView extends View {

    public TestView(Context context) {
        super(context);
    }

    public TestView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TestView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private int viewHeight;
    private int viewWidth;
    private Paint mPaint = new Paint();

    private void init() {

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        viewHeight = getMeasuredHeight();
        viewWidth = getMeasuredWidth();
        mPaint.setStrokeWidth(viewHeight);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        /*for (int i = 0; i < viewWidth; i++) {
            Shader shader = new LinearGradient(i, 0, i, viewHeight, Color.parseColor("#55FADADC"),
                    Color.parseColor("#00FADADC"), Shader.TileMode.CLAMP);
            mPaint.setShader(shader);
            canvas.drawLine(i, viewHeight/2, i, viewHeight , mPaint);
        }*/

        Shader shader = new LinearGradient(viewWidth/2, 0, viewWidth/2, viewHeight, Color.parseColor("#22ff0000"),
                Color.parseColor("#00ffffff"), Shader.TileMode.CLAMP);
        mPaint.setShader(shader);
        canvas.drawLine(0, viewHeight / 2, viewWidth, viewHeight / 2, mPaint);


    }
}

